package com.handydata.antifraud.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.handydata.common.convert.CommonBeanConvertor;
import com.handydata.common.web.AbsController;

import com.handydata.antifraud.common.exception.CityGpsBasedataExCode;
import com.handydata.antifraud.bo.citygpsbasedata.CityGpsBasedataReqBO;
import com.handydata.antifraud.bo.citygpsbasedata.CityGpsBasedataResBO;
import com.handydata.antifraud.vo.citygpsbasedata.CreateCityGpsBasedataReqVO;
import com.handydata.antifraud.vo.citygpsbasedata.CreateCityGpsBasedataResVO;
import com.handydata.antifraud.vo.citygpsbasedata.DeleteCityGpsBasedataReqVO;
import com.handydata.antifraud.vo.citygpsbasedata.DeleteCityGpsBasedataResVO;
import com.handydata.antifraud.vo.citygpsbasedata.ModifyCityGpsBasedataReqVO;
import com.handydata.antifraud.vo.citygpsbasedata.ModifyCityGpsBasedataResVO;
import com.handydata.antifraud.vo.citygpsbasedata.CityGpsBasedataBeanVO;
import com.handydata.antifraud.vo.citygpsbasedata.QueryCityGpsBasedataReqVO;
import com.handydata.antifraud.vo.citygpsbasedata.QueryCityGpsBasedataResVO;
import com.handydata.antifraud.service.CityGpsBasedataService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RequestMapping("/citygpsbasedata")
@RestController
public class CityGpsBasedataController extends AbsController {
	
	private static final Logger logger = LoggerFactory.getLogger(CityGpsBasedataController.class);
	
	@Autowired
	private CityGpsBasedataService cityGpsBasedataService;
	
	@ApiOperation(value="新增城市GPS码表", notes="新增城市GPS码表")
	@ApiImplicitParam(name = "req", value = "新增城市GPS码表请求对象", required = true, dataType = "CreateCityGpsBasedataReqVO", paramType = "body")
	@PostMapping("/create")
	public CreateCityGpsBasedataResVO createCityGpsBasedata(@RequestBody CreateCityGpsBasedataReqVO req) {
		try {
			logger.info("Execute createCityGpsBasedata, param is {}", req);
			CityGpsBasedataReqBO reqBO = CommonBeanConvertor.convert(req, CityGpsBasedataReqBO.class);
			CityGpsBasedataResBO resBO = cityGpsBasedataService.createCityGpsBasedata(reqBO);
			CreateCityGpsBasedataResVO res = CommonBeanConvertor.convert(resBO, CreateCityGpsBasedataResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, CreateCityGpsBasedataResVO.class, req, CityGpsBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="修改城市GPS码表", notes="修改城市GPS码表")
	@ApiImplicitParam(name = "req", value = "修改城市GPS码表请求对象", required = true, dataType = "ModifyCityGpsBasedataReqVO", paramType = "body")
	@PostMapping("/modify")
	public ModifyCityGpsBasedataResVO modifyCityGpsBasedata(@RequestBody ModifyCityGpsBasedataReqVO req) {
		try {
			logger.info("Execute modifyCityGpsBasedata, param is {}", req);
			CityGpsBasedataReqBO reqBO = CommonBeanConvertor.convert(req, CityGpsBasedataReqBO.class);
			CityGpsBasedataResBO resBO = cityGpsBasedataService.modifyCityGpsBasedata(reqBO);
			ModifyCityGpsBasedataResVO res = CommonBeanConvertor.convert(resBO, ModifyCityGpsBasedataResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, ModifyCityGpsBasedataResVO.class, req, CityGpsBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="删除城市GPS码表", notes="删除城市GPS码表")
	@ApiImplicitParam(name = "req", value = "修改城市GPS码表请求对象", required = true, dataType = "DeleteCityGpsBasedataReqVO", paramType = "body")
	@PostMapping("/remove")
	public DeleteCityGpsBasedataResVO deleteCityGpsBasedata(@RequestBody DeleteCityGpsBasedataReqVO req) {
		try {
			logger.info("Execute deleteCityGpsBasedata, param is {}", req);
			CityGpsBasedataReqBO reqBO = CommonBeanConvertor.convert(req, CityGpsBasedataReqBO.class);
			CityGpsBasedataResBO resBO = cityGpsBasedataService.deleteCityGpsBasedata(reqBO);
			DeleteCityGpsBasedataResVO res = CommonBeanConvertor.convert(resBO, DeleteCityGpsBasedataResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, DeleteCityGpsBasedataResVO.class, req, CityGpsBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
	@ApiOperation(value="查询城市GPS码表", notes="查询城市GPS码表")
	@ApiImplicitParam(name = "req", value = "查询城市GPS码表请求对象", required = true, dataType = "QueryCityGpsBasedataReqVO", paramType = "body")
	@PostMapping("/query")
	public QueryCityGpsBasedataResVO queryCityGpsBasedata(@RequestBody QueryCityGpsBasedataReqVO req) {
		try {
			logger.info("Execute queryCityGpsBasedata, param is {}", req);
			CityGpsBasedataReqBO reqBO = CommonBeanConvertor.convert(req, CityGpsBasedataReqBO.class);
			CityGpsBasedataResBO resBO = cityGpsBasedataService.queryCityGpsBasedata(reqBO);
			QueryCityGpsBasedataResVO res = CommonBeanConvertor.convert(resBO, QueryCityGpsBasedataResVO.class, CityGpsBasedataBeanVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, QueryCityGpsBasedataResVO.class, req, CityGpsBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
}
